<?php
require_once('ProductClass.php');
require_once('class.imageupload.php');  
$Product = new Product();

if(!isset($_POST['jual']))
{
    header("../page/HOME_jualbeli.php");    
}
else {
	$image = new ImageUploader(5000000,'../img/produk/'); 
	$image->setImage('fupload');
	if(!$image->checkSize())
		$errors[] = "Ukuran foto melebihi 5MB";
	if(!$image->checkExt())
		$errors[] = "Type file salah";
		
	if(!isset($errors)){
		$image->setImageName('fupload');
		$image->deleteExisting();
		$image->upload();	
	}
	else{
		echo "<h2>upload error</h2><br>";
		print_r($errors);
	}
	
	
    $nama_p = $Product->EscapeString($_POST['nama_p']);
    $kategori =$Product->EscapeString($_POST['Kategori']);
	$stok_p = $Product->EscapeString($_POST['stok_p']);
    $harga_p = $Product->EscapeString($_POST['harga_p']);
	$keterangan_p = $Product->EscapeString($_POST['keterangan_p']);
	$foto = $Product->EscapeString($_FILES['fupload']['name']);

    $Product->AddProduct($nama_p,$kategori,$stok_p,$harga_p,$keterangan_p,$foto);
}

$Product->Disconnect();
 
?>
